package com.wugh.fast.demo.config.bean;

import com.netflix.hystrix.strategy.HystrixPlugins;
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
import com.wugh.fast.kernel.core.thread.ContextAwareCallable;
import org.springframework.stereotype.Component;

import java.util.concurrent.Callable;

/**
 * 说明: 处理hystrix获取上下文问题
 *
 * @author wugh
 * @date 2020-01-15 13:51
 */
@Component
public class RequestAttributeHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {
    public RequestAttributeHystrixConcurrencyStrategy() {
        HystrixPlugins.reset();
        HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
    }

    @Override
    public <T> Callable<T> wrapCallable(Callable<T> callable) {
        return ContextAwareCallable.build(callable);
    }
}
